#include <cstdio>
#include <cstring>

#define MAXH 40+5
#define MAXW 10+5
#define MAXN 400+10

int H, W, N;
int MAP[MAXH][MAXW];
bool G[MAXN][MAXN];
bool vis[MAXN];
int match[MAXN];

int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

bool dfs(int n) {
	for (int i=1; i<=N; i++) {
		if (G[n][i] && !vis[i]) {
			vis[i] = true;
			if (!match[i] || dfs(match[i])) {
				match[i] = n;
				return true;
			}
		}
	}
	return false;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &H, &W);
		getchar();
		memset(MAP, 0, sizeof(MAP));
		int index = 1;
		for (int i=1; i<=H; i++) {
			for (int j=1; j<=W; j++) {
				char c;
				scanf("%c", &c);
				if (c=='*') MAP[i][j]=index++;
			}
			getchar();
		}
		N = index-1;
		memset(G, 0, sizeof(G));
		for (int i=1; i<=H; i++) {
			for (int j=1; j<=W; j++) {
				if (!MAP[i][j]) continue;
				for (int k=0; k<4; k++) {
					int ti = i+dir[k][0];
					int tj = j+dir[k][1];
					if (ti<1 || ti>H || tj<1 || tj>W) continue;
					if (MAP[ti][tj]) G[MAP[i][j]][MAP[ti][tj]] = true;
				}
			}
		}
//		for (int i=1; i<=index; i++) {
//			for (int j=1; j<=index; j++) {
//				printf("%c", G[i][j]?'1':'0');
//			}
//			printf("\n");
//		}
		memset(match, 0, sizeof(match));
		int cnt = 0;
		for (int i=1; i<=N; i++) {
			memset(vis, 0, sizeof(vis));
			if (dfs(i)) cnt++;
		}
		printf("%d\n", N-cnt/2);
	}
	return 0;
}
